const crypto = require('crypto');
const Response = require('./Response')
const {
	getTime,
} = require('../utils/dateUtils')
const {
	_crawlerMongo,
} = global

module.exports = {

	/**
	 * 资源列表
	 * @param  {[type]} params [description]
	 * @return {[type]}        [description]
	 */
	list: async function(params) {
		let {
			col_name,
			pn = 1,
			ps = 10,
		} = params
		let skip = (pn - 1) * ps
		let col = await _crawlerMongo.getCollection(col_name)
		let total = await col.count()
		let docs = await col.find().sort({
			modify_time: -1
		}).skip(skip).limit(ps).toArray()
		return new Response('000', '成功', {
			total,
			docs,
		})
	},

}

/**
 * 密码加密
 * @param  {[type]} password [description]
 * @return {[type]}          [description]
 */
function encPwd(password) {
	return crypto.createHash('md5').update(password).digest('hex');
}